<template>
    <div class="common-layout">
        <el-container>
            <el-aside width="200px">
                <el-menu :router="true" active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
                    default-active="2" text-color="#fff" @open="handleOpen" @close="handleClose">
                    <template v-for="item in menudata" :key="item">
                        <el-menu-item v-if="!item.children" :index="item.path">
                            {{ item.label }}
                        </el-menu-item>
                        <el-sub-menu v-else :index="item.id">
                            <template #title>
                                <span>{{ item.label }}</span>
                            </template>
                            <el-menu-item v-for="sonItem in item.children " :key="sonItem" :index="sonItem.path">{{ sonItem.label }}
                           </el-menu-item>
                        </el-sub-menu>
                    </template>
                </el-menu>
            </el-aside>
            <el-container>
                <el-header>欢迎你{{ name }}
                    <el-button @click="changename()">退出登录</el-button>
                </el-header>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router';
import getItemt from '../../Threedes/menudata';
import getRoutes, { clearCrudRoute } from "../../Threedes/router";
import {useStore} from "vuex";
// import { useRouteStore } from "../../piniaStore/index"
const router = useRouter();


let $store = useStore();

if(!$store.state.isAddRoute){
    getRoutes();
}
    
const menudata = reactive(getItemt());

const $router = useRouter();
const dataitem = reactive(getItemt())
const handleOpen = (key: string, keyPath: string[]) => {
}
const handleClose = (key: string, keyPath: string[]) => {
}
const name = ref()
const username = sessionStorage.getItem("username")
name.value = username
const changename = () => {
    sessionStorage.clear();
    clearCrudRoute()
     $store.commit({
        type: "setIsAddRoute",
        isAddRoute: false,
    });
    $router.push("/login")
}


</script>

<style scoped>
.common-layout {
    width: 100%;
    height: 100%;
}

.el-container {
    width: 100%;
    height: 100%;
}

.el-aside {
    width: 200px;
    height: 100%;
    background-color: rgb(84, 92, 100);
}

.el-header {
    width: 100%;
    height: 120px;
    background-color: rgb(100, 207, 249);
}
</style>